package com.itheima.eurekaprovider.controller;

import com.itheima.eurekaprovider.entity.User;
import com.itheima.eurekaprovider.service.PortService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
public class HelloController {
    @Autowired
    PortService portService;
   @GetMapping(value="/hello")
    public String sayHello() {
       String s = "Hello Feign! from provider\n" + portService.getPort();
        return s;
    }
    @GetMapping("/hello1")
    public String hello(@RequestParam String name){
       String s = "Hello from provider\n"
               + portService.getPort()
               + " 参数="+name;
       return s;
    }
    @GetMapping(value="/hello2")
    public String sayHello(@RequestParam String username,@RequestHeader(value="age") Integer age) {
        String s = "Hello from provider\n"
                + portService.getPort()
                + " 参数="+username+" "+age;
        return s;
    }
    //对象绑定方法在分布式环境下传递会出错
    @PostMapping(value="/hello3")
    public String sayHello2( User user) {
        System.out.println("hello3 provider== "+user);
        String s = "Hello from provider /hello3 绑定 \n"
                + portService.getPort()
                + " 参数="+user;
        return s;
    }
    //重点掌握 JSON参数传递
    @PostMapping(value="/hello4")
    public String sayHello(@RequestBody User user) {
    //此处放入 学号:姓名:机器名
        String mid = "[学号:姓名:机器名]";
        String s = "Hello from provider \n" + mid + " "
                + portService.getPort()
                + " 参数="+user;
        return s;
    }
}
